//
//  SEGReadFileViewController.m
//  SEGUhomeStandard
//
//  Created by 山刘 on 2018/8/16.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGReadFileViewController.h"
#if __has_include(<Commom/SEGColorManager.h>)
#import <Commom/SEGColorManager.h>
#else
#import "SEGColorManager.h"
#endif
#import <WebKit/WebKit.h>

@interface SEGReadFileViewController ()<WKNavigationDelegate>
/// 主视图webView
@property (nonatomic, strong) WKWebView* webView;
@end

@implementation SEGReadFileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kColor_W;
    [self.view addSubview:self.webView];
    self.navigationController.navigationBarHidden = NO;
    [self segLayoutPageSubviews];
}

// 界面布局
- (void)segLayoutPageSubviews
{
    self.webView.frame = self.view.bounds;
    
    NSURL* url =[[NSURL alloc] initWithString:self.linkURL];
    NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [self.webView loadRequest:request];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark - event response 响应事件

#pragma mark - private methods 私有方法

#pragma mark - getters and setters

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    NSString *injectionJSString = @"var script = document.createElement('meta');"
    "script.name = 'viewport';"
    "script.content=\"width=device-width, user-scalable=no\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    [webView evaluateJavaScript:injectionJSString completionHandler:nil];
}

- (WKWebView *)webView
{
    if (!_webView) {
        _webView = [[WKWebView alloc] init];
        _webView.backgroundColor = [UIColor clearColor];
        _webView.navigationDelegate = self;
        _webView.scrollView.showsHorizontalScrollIndicator = NO;
    }
    return _webView;
}
@end
